package test1;

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.opengl.*;
import org.lwjgl.*;

public class TimerDemo
{
	/*********************************** BEGIN CONSTANTS *******************************************/
	public static final int WIDTH = 800;
	public static final int HEIGHT = 600;
	public static final int ZNEAR = 1;

	/*********************************** END CONSTANTS *******************************************/

	private long lastFrame;
	
	private long getTime()
	{
		return (Sys.getTime() * 1000) / Sys.getTimerResolution();
	}
	
	private int getDelta()
	{
		long currentTime = getTime();
		int delta = (int) (currentTime - lastFrame);
		lastFrame = getTime();
		return delta;
	}
	
	public TimerDemo()
	{
		try
		{
			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
			Display.setTitle("Hello, LWJGL!");
			Display.create();
		} catch (LWJGLException e)
		{
			e.printStackTrace();
		}
		
		int x = 100;
		int y = 100;
		int dx = 1;
		int dy = 1;

		// Initialize OpenGL
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, WIDTH, HEIGHT, 0, ZNEAR, -1);
		glMatrixMode(GL_MODELVIEW);

		
		lastFrame = getTime();
		while (!Display.isCloseRequested())
		{
			glClear(GL_COLOR_BUFFER_BIT);
			
			int delta = getDelta();
			x += delta * dx * 0.1;
			y += delta * dy * 0.1;
			
			glRecti(x,y,x+30, y+30);

			Display.update();
			Display.sync(60);
		}
		Display.destroy();
	}

	public static void main(String[] args)
	{
		new TimerDemo();

	}

}
